﻿<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="XProject.DataVisit.Model.Doc" %>
<%@ Import Namespace="XProject.DataVisit.BLL" %>
<%@ Import Namespace="XProject.DataVisit.Factory" %>
<%
    string DocName = Request["DocName"];
    string DocPrice = Request["DocPrice"];
    string DocCustom = Request["DocCustom"];
    bool isGood = false;
    if (Request["isGood"] != null)
    {
        isGood = true;
    }
    string GoodName = Request["GoodName"];
    string GoodC = Request["GoodC"];

    string Remark = Request["Remark"];
    string FileName = Request.Files["Moreinfo"].FileName;
    Stream filec = Request.Files["Moreinfo"].InputStream;
    int FileLen = Request.Files["Moreinfo"].ContentLength;
    byte[] fileData = new byte[FileLen];
    filec.Read(fileData, 0, FileLen);
    string filetype = Path.GetExtension(Request.Files["Moreinfo"].FileName);
    string DN= Guid.NewGuid().ToString() + filetype;
    string DocPath = Server.MapPath("../") + "/DocumentFile/" + DN;
    File.WriteAllBytes(DocPath, fileData);

    DocumentInfo di = new DocumentInfo();
    di.DocCustom = DocCustom;
    di.DocName = DocName;
    di.DocPrice = Convert.ToDouble(DocPrice);
    di.DocState = 0;
    di.GoodsCount = Convert.ToDouble(GoodC);
    di.GoodsName = GoodName;
    di.IsGoods = isGood;
    di.LastUpdate = DateTime.Now;
    di.MoreInfo = "DocumentFile/" + DN;
    di.Remark = Remark;
    if(Session["UserInfo"]!=null)
    {
        var u=Session["UserInfo"] as XProject.DataVisit.Model.UserInfo;
        di.UserID = u.PID;
    }
    DaoFactory.DocumentInfoDao.Save(di);
    
    
    Dictionary<string, object> data = new Dictionary<string, object>();
    data.Add("success", true);
    Response.Clear();
    Response.Write(Newtonsoft.Json.JavaScriptConvert.SerializeObject(data));
    Response.End();
 %>